﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

using Hangjing.Model;
using Hangjing.Common;
using Hangjing.SQLServerDAL;

/// <summary>
/// 根据oepnid返回信息
/// </summary>
public partial class AndroidAPI_GetUserInfoByOpenid : APIPageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Clear();
        StringBuilder json = new StringBuilder("");
        ECustomer dal = new ECustomer();
        string openid = Request["openid"].ToString();
        string recommenderOpenid = HjNetHelper.GetPostParam("recommenderOpenid");
        ECustomerInfo info = new ECustomerInfo();
        info = dal.GetModelByOpenid(openid);
        if (info != null)
        {

        }
        else
        {
            int userid = dal.addByOpenid("", openid);
            info = dal.GetModel(userid);
            //设置推荐人
            if (recommenderOpenid !=null && recommenderOpenid.Length > 0 &&  info.RID =="0")
            {
                ECustomerInfo recommender = dal.GetModelByOpenid(recommenderOpenid);
                if (recommender != null)
                {
                    dal.UpdateUserValue(info.DataID, "rid", recommender.DataID);
                    Hangjing.AppLog.OperationLog.Info("[小程序]用户：" + recommender.DataID + " 推荐了" + info.DataID);
                }
            }

        }

        Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(info));
        Response.End();
    }
}
